home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / utils / whichsrc.arc / WHICH.C < prev   
C/C++ Source or Header  |  1990-03-20  |  2KB  |  84 lines

  1. #define DELIMETER ','
  2.  
  3. #include <stdio.h>
  4.  
  5. char *getenv();
  6. char *index();
  7.  
  8. int
  9. main(ac,av)
  10. char **av;
  11. {
  12.     char *path, *cp;
  13.     char buf[200];
  14.     char prog[200];
  15.     char patbuf[512];
  16.     int quit, none;
  17.  
  18.     if (ac < 2) {
  19.         fprintf(stderr, "Usage: %s cmd [cmd, ..]\n", *av);
  20.         exit(1);
  21.     }
  22.     av[ac] = 0;
  23.     for(av++ ; *av; av++) {
  24.  
  25.         quit = 0;
  26.         none = 1;
  27.     if ((path = getenv("PATH")) == NULL) {
  28.         fprintf(stderr, "Null path.\n");
  29.         exit(0);
  30.     }
  31.         strcpy(patbuf, path);
  32.         path = patbuf;
  33.         cp = path;
  34.  
  35.         while(1) {
  36.             cp = index(path, DELIMETER);
  37.             if (cp == NULL) 
  38.                 quit++;
  39.             else
  40.                 *cp = '\0';
  41.  
  42.         if (strcmp(path,"") == (char *)NULL && quit == 0) {
  43.         sprintf(buf, "%s.\\%s", path, *av);
  44.         } else 
  45.         sprintf(buf, "%s\\%s", path, *av);
  46.     
  47. /* fprintf(stderr,"Trying %s, path %s\n",buf,path); */
  48.  
  49.             path = ++cp;
  50.  
  51.             if (access(buf, 1) == 0) {
  52.                 printf("%s\n", buf);
  53.                 none = 0;
  54.             }
  55.         
  56.             sprintf(prog, "%s.%s", buf, "prg");
  57.             if (access(prog, 1) == 0) {
  58.                 printf("%s\n", prog);
  59.                 none = 0;
  60.             }
  61.         
  62.             sprintf(prog, "%s.%s", buf, "ttp");
  63.             if (access(prog, 1) == 0) {
  64.                 printf("%s\n", prog);
  65.                 none = 0;
  66.             }
  67.         
  68.             sprintf(prog, "%s.%s", buf, "tos");
  69.             if (access(prog, 1) == 0) {
  70.                 printf("%s\n", prog);
  71.                 none = 0;
  72.             }
  73.             if (quit) {
  74.                 if (none)
  75.                     printf("No %s in %s\n", *av, getenv("PATH"));
  76.                 break;
  77.             }
  78.         }
  79.     }
  80.     exit(0);
  81. }
  82.  
  83.  
  84.